package com.example.lib5.company_interface.StringsAndArrays.test2;

/**
 * 创建日期：2022/6/7 0007 14:37
 *
 * @author tony.sun
 * 类说明：
 */
public class StringOperateImpl implements IStringOperate {
    @Override
    public String[] split(String string, String split) {
        if (string.isEmpty()) {
            System.out.println("字符串为空");
            return null;
        }
        String[] strings=new String[string.length()];
        int index=0;
        while (true){
            if (string.contains(split)) {
                int indexStr = string.indexOf(split);//"ab&&2"
                strings[index]=string.substring(0,indexStr);
                index++;
                string=string.substring(indexStr+2);
            }else {
                strings[index]=string;
                break;
            }
        }
        return strings;
    }
    @Override
    public String group(String[] strings, String group) {
        if (strings==null||strings.length==0) {
            System.out.println("数组为空");
            return "";
        }
        StringBuilder stringBuilder=new StringBuilder();
        for (String s : strings) {
            stringBuilder.append(s);
            stringBuilder.append("&&");
        }
        stringBuilder.delete(stringBuilder.length()-2,stringBuilder.length());
        return stringBuilder.toString();
    }
}
